﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using PMSGSC.BLL;
using PMSGSC.Common;

namespace PMSGSC.App
{
    public partial class frmConsumableStock : DevExpress.XtraEditors.XtraForm
    {
        public frmConsumableStock(frmMain objMain)
        {
            InitializeComponent();
            List<Stock> stocks = Stock_BLL.GetAll(frmMain.ship.Ship_ID);
            cbbStockName.Properties.Items.Add("All");
            foreach (Stock stock in stocks)
            {
                cbbStockName.Properties.Items.Add(stock.StockName);
            }
            FromDate.DateTime = DateTime.Now.Date.AddMonths(-1);
            ToDate.DateTime = DateTime.Now.Date;
            main = objMain;
        }
        private frmMain main;
        private List<InvoiceDetail> resultList;
        private void btnOk_Click(object sender, EventArgs e)
        {
            frmProcessBar pb = new frmProcessBar();
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                LoadSkinToForm();
                pb.ShowDialog();
            }
            ));
            thread.Start();

            if (cbbTransType.Text == "Out")
                resultList = InvoiceDetail_BLL.ConsumableStock(FromDate.DateTime.Date, ToDate.DateTime.Date, cbbStockName.Text, false);
            else
                resultList = InvoiceDetail_BLL.ConsumableStock(FromDate.DateTime.Date, ToDate.DateTime.Date, cbbStockName.Text, true);

            if (resultList.Count > 0)
            {
                frmReViewConsumable reView = new frmReViewConsumable(resultList);
                reView.MdiParent = main;
                reView.Show();

                if (pb.InvokeRequired)
                    pb.BeginInvoke(new Action(() => pb.Close()));


                this.Close();
            }
            else
            {
                if (pb.InvokeRequired)
                    pb.BeginInvoke(new Action(() => pb.Close()));
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private static void LoadSkinToForm()
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.LookAndFeel.DefaultLookAndFeel obj = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            try
            {
                LookAndFeelSettings.Load("LookAndFeelSettings.dat");
            }
            catch
            {
                obj.LookAndFeel.SetSkinStyle("Blue");
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            cbbStockName.SelectedIndex = 0;
            cbbTransType.SelectedIndex = 0;
            FromDate.DateTime = DateTime.Now.Date.AddMonths(-1);
            ToDate.DateTime = DateTime.Now.Date;
        }
    }
}